package com.shop2cn.iapi.prodstock.testcase;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.activitymgt.parameter.AddactivityBean;
import com.shop2cn.iapi.prodstock.parameter.PreOrderReduceCatalogDto;
import com.shop2cn.iapi.prodstock.parameter.ReduceStockListForPreOrderBean;
import com.shop2cn.iapi.prodstock.service.ReduceStockListForPreOrderCall;
import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.ProductDetailsDto;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.AgentProductCallServiceV2;
import com.ymttest.database.model.GodProductActivityStock;
import com.ymttest.database.sqlwapper.GodProductActivityStockWapper;
import com.ymttest.utils.AgentUsers;
import com.ymttest.utils.TestDataManager;
/**
*下单扣减库存Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_ReduceStockListForPreOrder{
	private static ReduceStockListForPreOrderBean reducestocklistforpreorderBean;
	private static ReduceStockListForPreOrderCall reducestocklistforpreorderCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("下单扣减库存Test");
	}

	
	@Before
	public void caseUp() {
		reducestocklistforpreorderBean=new ReduceStockListForPreOrderBean();
		reducestocklistforpreorderCall=new ReduceStockListForPreOrderCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(reducestocklistforpreorderCall.getOpurl());
	}
	

	@After
	public void caseDown() {
		Logger.end();
	}
	

	// 渠道商
	private static int rootUserId = AgentUsers.rootUserId;
	private static String rootUserName = "NickautoTest";
	// 渠道商->代理商1
	private static int agentUserId1 = AgentUsers.agentUserId1;
	private static String agentUserName1 = "NickautoTest";
	// vip渠道
	private static int vipRootUserId = AgentUsers.vipRootUserId;
	private static String vipRootUserName = "NickautoTest";
	private static int csId = AgentUsers.csId;
	// vip渠道->代理
	private static int vipAgentUserId1 = AgentUsers.vipAgentUserId1;
	private static String vipAgentUserName1 = "dgsq408897016";
	private static int csId1 = AgentUsers.csId1;

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForPreOrder_001() {
		Logger.start(true, "真实40件，虚拟30件，下单十件货-----真实30件，虚拟30件");
		try {

			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, true);
			addAgentProductBean.getCatalogList().get(0).setVirtualStock(30);
			addAgentProductBean.getCatalogList().get(0).setStock(40);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			ProductDetailsDto productDetailsDto = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
			
			List<PreOrderReduceCatalogDto> catalogStockList = new ArrayList<PreOrderReduceCatalogDto>();
			PreOrderReduceCatalogDto preOrderReduceCatalogDto = new PreOrderReduceCatalogDto();
			preOrderReduceCatalogDto.setPreOrderId(Long.parseLong(TestDataManager.getRandomNum(10)));
			preOrderReduceCatalogDto.setActivityId(0);
			preOrderReduceCatalogDto.setBuyerId(AgentUsers.csId1);
			preOrderReduceCatalogDto.setCatalogId(productDetailsDto.getCatalogList().get(0).getCatalogId());
			preOrderReduceCatalogDto.setCatalogType(0);
			preOrderReduceCatalogDto.setProductId(productId);
			preOrderReduceCatalogDto.setSellerId(rootUserId);
			preOrderReduceCatalogDto.setBuyCount(10);
			preOrderReduceCatalogDto.setProductLimitNumber(0);
			preOrderReduceCatalogDto.setProductLimitStartTime("0001-01-01T00:00:00");
			preOrderReduceCatalogDto.setActivityLimitNumber(0);
			
			reducestocklistforpreorderBean.setCatalogList(Arrays.asList(preOrderReduceCatalogDto));
			reducestocklistforpreorderCall.setData(reducestocklistforpreorderBean);
			reducestocklistforpreorderCall.callService();			
			Logger.verifyEquals("200", reducestocklistforpreorderCall.getString("Code"), "验证code");
			
			ProductDetailsDto productDetailsDto2 = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
			
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getStock()-10,productDetailsDto2.getCatalogList().get(0).getStock(),"验证库存");
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getRealStock()-10,productDetailsDto2.getCatalogList().get(0).getRealStock(),"验证真实库存");
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getVirtualStock(),productDetailsDto2.getCatalogList().get(0).getVirtualStock(),"验证虚拟库存");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForPreOrder_002() {
		Logger.start(true, "真实40件，虚拟30件，下单40件货-----真实0件，虚拟30件");
		try {

			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, true);
			addAgentProductBean.getCatalogList().get(0).setVirtualStock(30);
			addAgentProductBean.getCatalogList().get(0).setStock(40);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			ProductDetailsDto productDetailsDto = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
			
			List<PreOrderReduceCatalogDto> catalogStockList = new ArrayList<PreOrderReduceCatalogDto>();
			PreOrderReduceCatalogDto preOrderReduceCatalogDto = new PreOrderReduceCatalogDto();
			preOrderReduceCatalogDto.setPreOrderId(Long.parseLong(TestDataManager.getRandomNum(10)));
			preOrderReduceCatalogDto.setActivityId(0);
			preOrderReduceCatalogDto.setBuyerId(AgentUsers.csId1);
			preOrderReduceCatalogDto.setCatalogId(productDetailsDto.getCatalogList().get(0).getCatalogId());
			preOrderReduceCatalogDto.setCatalogType(0);
			preOrderReduceCatalogDto.setProductId(productId);
			preOrderReduceCatalogDto.setSellerId(rootUserId);
			preOrderReduceCatalogDto.setBuyCount(40);
			preOrderReduceCatalogDto.setProductLimitNumber(0);
			preOrderReduceCatalogDto.setProductLimitStartTime("0001-01-01T00:00:00");
			preOrderReduceCatalogDto.setActivityLimitNumber(0);
			
			reducestocklistforpreorderBean.setCatalogList(Arrays.asList(preOrderReduceCatalogDto));
			reducestocklistforpreorderCall.setData(reducestocklistforpreorderBean);
			reducestocklistforpreorderCall.callService();			
			Logger.verifyEquals("200", reducestocklistforpreorderCall.getString("Code"), "验证code");
			
			ProductDetailsDto productDetailsDto2 = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
			
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getStock()-40,productDetailsDto2.getCatalogList().get(0).getStock(),"验证库存");
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getRealStock()-40,productDetailsDto2.getCatalogList().get(0).getRealStock(),"验证真实库存");
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getVirtualStock(),productDetailsDto2.getCatalogList().get(0).getVirtualStock(),"验证虚拟库存");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForPreOrder_003() {
		Logger.start(true, "真实40件，虚拟30件，下单50件货-----真实0件，虚拟20件");
		try {

			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, true);
			addAgentProductBean.getCatalogList().get(0).setVirtualStock(30);
			addAgentProductBean.getCatalogList().get(0).setStock(40);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			ProductDetailsDto productDetailsDto = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
			
			List<PreOrderReduceCatalogDto> catalogStockList = new ArrayList<PreOrderReduceCatalogDto>();
			PreOrderReduceCatalogDto preOrderReduceCatalogDto = new PreOrderReduceCatalogDto();
			preOrderReduceCatalogDto.setPreOrderId(Long.parseLong(TestDataManager.getRandomNum(10)));
			preOrderReduceCatalogDto.setActivityId(0);
			preOrderReduceCatalogDto.setBuyerId(AgentUsers.csId1);
			preOrderReduceCatalogDto.setCatalogId(productDetailsDto.getCatalogList().get(0).getCatalogId());
			preOrderReduceCatalogDto.setCatalogType(0);
			preOrderReduceCatalogDto.setProductId(productId);
			preOrderReduceCatalogDto.setSellerId(rootUserId);
			preOrderReduceCatalogDto.setBuyCount(50);
			preOrderReduceCatalogDto.setProductLimitNumber(0);
			preOrderReduceCatalogDto.setProductLimitStartTime("0001-01-01T00:00:00");
			preOrderReduceCatalogDto.setActivityLimitNumber(0);
			
			reducestocklistforpreorderBean.setCatalogList(Arrays.asList(preOrderReduceCatalogDto));
			reducestocklistforpreorderCall.setData(reducestocklistforpreorderBean);
			reducestocklistforpreorderCall.callService();			
			Logger.verifyEquals("200", reducestocklistforpreorderCall.getString("Code"), "验证code");
			
			ProductDetailsDto productDetailsDto2 = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
			
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getStock()-50,productDetailsDto2.getCatalogList().get(0).getStock(),"验证库存");
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getRealStock()-40,productDetailsDto2.getCatalogList().get(0).getRealStock(),"验证真实库存");
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getVirtualStock()-10,productDetailsDto2.getCatalogList().get(0).getVirtualStock(),"验证虚拟库存");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForPreOrder_004() {
		Logger.start(true, "真实40件，虚拟30件，下单70件货-----真实0件，虚拟0件");
		try {

			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, true);
			addAgentProductBean.getCatalogList().get(0).setVirtualStock(30);
			addAgentProductBean.getCatalogList().get(0).setStock(40);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			ProductDetailsDto productDetailsDto = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
			
			List<PreOrderReduceCatalogDto> catalogStockList = new ArrayList<PreOrderReduceCatalogDto>();
			PreOrderReduceCatalogDto preOrderReduceCatalogDto = new PreOrderReduceCatalogDto();
			preOrderReduceCatalogDto.setPreOrderId(Long.parseLong(TestDataManager.getRandomNum(10)));
			preOrderReduceCatalogDto.setActivityId(0);
			preOrderReduceCatalogDto.setBuyerId(AgentUsers.csId1);
			preOrderReduceCatalogDto.setCatalogId(productDetailsDto.getCatalogList().get(0).getCatalogId());
			preOrderReduceCatalogDto.setCatalogType(0);
			preOrderReduceCatalogDto.setProductId(productId);
			preOrderReduceCatalogDto.setSellerId(rootUserId);
			preOrderReduceCatalogDto.setBuyCount(70);
			preOrderReduceCatalogDto.setProductLimitNumber(0);
			preOrderReduceCatalogDto.setProductLimitStartTime("0001-01-01T00:00:00");
			preOrderReduceCatalogDto.setActivityLimitNumber(0);
			
			reducestocklistforpreorderBean.setCatalogList(Arrays.asList(preOrderReduceCatalogDto));
			reducestocklistforpreorderCall.setData(reducestocklistforpreorderBean);
			reducestocklistforpreorderCall.callService();			
			Logger.verifyEquals("200", reducestocklistforpreorderCall.getString("Code"), "验证code");
			
			ProductDetailsDto productDetailsDto2 = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
			
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getStock()-70,productDetailsDto2.getCatalogList().get(0).getStock(),"验证库存");
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getRealStock()-40,productDetailsDto2.getCatalogList().get(0).getRealStock(),"验证真实库存");
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getVirtualStock()-30,productDetailsDto2.getCatalogList().get(0).getVirtualStock(),"验证虚拟库存");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForPreOrder_005() {
		Logger.start(true, "订单编号为空，失败");
		try {

			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, true);
			addAgentProductBean.getCatalogList().get(0).setVirtualStock(30);
			addAgentProductBean.getCatalogList().get(0).setStock(40);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			ProductDetailsDto productDetailsDto = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
			
			List<PreOrderReduceCatalogDto> catalogStockList = new ArrayList<PreOrderReduceCatalogDto>();
			PreOrderReduceCatalogDto preOrderReduceCatalogDto = new PreOrderReduceCatalogDto();
//			preOrderReduceCatalogDto.setPreOrderId(Long.parseLong(TestDataManager.getRandomNum(10)));
			preOrderReduceCatalogDto.setActivityId(0);
			preOrderReduceCatalogDto.setBuyerId(AgentUsers.csId1);
			preOrderReduceCatalogDto.setCatalogId(productDetailsDto.getCatalogList().get(0).getCatalogId());
			preOrderReduceCatalogDto.setCatalogType(0);
			preOrderReduceCatalogDto.setProductId(productId);
			preOrderReduceCatalogDto.setSellerId(rootUserId);
			preOrderReduceCatalogDto.setBuyCount(10);
			preOrderReduceCatalogDto.setProductLimitNumber(0);
			preOrderReduceCatalogDto.setProductLimitStartTime("0001-01-01T00:00:00");
			preOrderReduceCatalogDto.setActivityLimitNumber(0);
			
			reducestocklistforpreorderBean.setCatalogList(Arrays.asList(preOrderReduceCatalogDto));
			reducestocklistforpreorderCall.setData(reducestocklistforpreorderBean);
			reducestocklistforpreorderCall.callService();			
			Logger.verifyEquals("201", reducestocklistforpreorderCall.getString("Code"), "验证code");
			
			ProductDetailsDto productDetailsDto2 = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
			
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getStock(),productDetailsDto2.getCatalogList().get(0).getStock(),"验证库存");
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getRealStock(),productDetailsDto2.getCatalogList().get(0).getRealStock(),"验证真实库存");
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getVirtualStock(),productDetailsDto2.getCatalogList().get(0).getVirtualStock(),"验证虚拟库存");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForPreOrder_006() {
		Logger.start(true, "请求两次，有幂等");
		try {

			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, true);
			addAgentProductBean.getCatalogList().get(0).setVirtualStock(30);
			addAgentProductBean.getCatalogList().get(0).setStock(40);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			ProductDetailsDto productDetailsDto = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
			
			List<PreOrderReduceCatalogDto> catalogStockList = new ArrayList<PreOrderReduceCatalogDto>();
			PreOrderReduceCatalogDto preOrderReduceCatalogDto = new PreOrderReduceCatalogDto();
			preOrderReduceCatalogDto.setPreOrderId(Long.parseLong(TestDataManager.getRandomNum(10)));
			preOrderReduceCatalogDto.setActivityId(0);
			preOrderReduceCatalogDto.setBuyerId(AgentUsers.csId1);
			preOrderReduceCatalogDto.setCatalogId(productDetailsDto.getCatalogList().get(0).getCatalogId());
			preOrderReduceCatalogDto.setCatalogType(0);
			preOrderReduceCatalogDto.setProductId(productId);
			preOrderReduceCatalogDto.setSellerId(rootUserId);
			preOrderReduceCatalogDto.setBuyCount(10);
			preOrderReduceCatalogDto.setProductLimitNumber(0);
			preOrderReduceCatalogDto.setProductLimitStartTime("0001-01-01T00:00:00");
			preOrderReduceCatalogDto.setActivityLimitNumber(0);
			
			reducestocklistforpreorderBean.setCatalogList(Arrays.asList(preOrderReduceCatalogDto));
			reducestocklistforpreorderCall.setData(reducestocklistforpreorderBean);
			reducestocklistforpreorderCall.callService();			
			ReduceStockListForPreOrderCall call1=reducestocklistforpreorderCall;
			call1.callService();	
			Logger.verifyEquals("200", reducestocklistforpreorderCall.getString("Code"), "验证code");
			Logger.verifyEquals("200", call1.getString("Code"), "验证code");
			
			
			ProductDetailsDto productDetailsDto2 = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
			
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getStock()-10,productDetailsDto2.getCatalogList().get(0).getStock(),"验证库存");
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getRealStock()-10,productDetailsDto2.getCatalogList().get(0).getRealStock(),"验证真实库存");
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getVirtualStock(),productDetailsDto2.getCatalogList().get(0).getVirtualStock(),"验证虚拟库存");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForPreOrder_007() {
		Logger.start(true, "规格编号为空，失败");
		try {

			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, true);
			addAgentProductBean.getCatalogList().get(0).setVirtualStock(30);
			addAgentProductBean.getCatalogList().get(0).setStock(40);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			ProductDetailsDto productDetailsDto = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
			
			List<PreOrderReduceCatalogDto> catalogStockList = new ArrayList<PreOrderReduceCatalogDto>();
			PreOrderReduceCatalogDto preOrderReduceCatalogDto = new PreOrderReduceCatalogDto();
			preOrderReduceCatalogDto.setPreOrderId(Long.parseLong(TestDataManager.getRandomNum(10)));
			preOrderReduceCatalogDto.setActivityId(0);
			preOrderReduceCatalogDto.setBuyerId(AgentUsers.csId1);
			preOrderReduceCatalogDto.setCatalogType(0);
			preOrderReduceCatalogDto.setProductId(productId);
			preOrderReduceCatalogDto.setSellerId(rootUserId);
			preOrderReduceCatalogDto.setBuyCount(10);
			preOrderReduceCatalogDto.setProductLimitNumber(0);
			preOrderReduceCatalogDto.setProductLimitStartTime("0001-01-01T00:00:00");
			preOrderReduceCatalogDto.setActivityLimitNumber(0);
			
			reducestocklistforpreorderBean.setCatalogList(Arrays.asList(preOrderReduceCatalogDto));
			reducestocklistforpreorderCall.setData(reducestocklistforpreorderBean);
			reducestocklistforpreorderCall.callService();			
			Logger.verifyEquals("201", reducestocklistforpreorderCall.getString("Code"), "验证code");
			
			ProductDetailsDto productDetailsDto2 = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
			
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getStock(),productDetailsDto2.getCatalogList().get(0).getStock(),"验证库存");
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getRealStock(),productDetailsDto2.getCatalogList().get(0).getRealStock(),"验证真实库存");
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getVirtualStock(),productDetailsDto2.getCatalogList().get(0).getVirtualStock(),"验证虚拟库存");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForPreOrder_008() {
		Logger.start(true, "真实40件，虚拟30件，下单40件货-----库存不足，失败");
		try {

			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, true);
			addAgentProductBean.getCatalogList().get(0).setVirtualStock(30);
			addAgentProductBean.getCatalogList().get(0).setStock(40);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			ProductDetailsDto productDetailsDto = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
			
			List<PreOrderReduceCatalogDto> catalogStockList = new ArrayList<PreOrderReduceCatalogDto>();
			PreOrderReduceCatalogDto preOrderReduceCatalogDto = new PreOrderReduceCatalogDto();
			preOrderReduceCatalogDto.setPreOrderId(Long.parseLong(TestDataManager.getRandomNum(10)));
			preOrderReduceCatalogDto.setActivityId(0);
			preOrderReduceCatalogDto.setBuyerId(AgentUsers.csId1);
			preOrderReduceCatalogDto.setCatalogId(productDetailsDto.getCatalogList().get(0).getCatalogId());
			preOrderReduceCatalogDto.setCatalogType(0);
			preOrderReduceCatalogDto.setProductId(productId);
			preOrderReduceCatalogDto.setSellerId(rootUserId);
			preOrderReduceCatalogDto.setBuyCount(80);
			preOrderReduceCatalogDto.setProductLimitNumber(0);
			preOrderReduceCatalogDto.setProductLimitStartTime("0001-01-01T00:00:00");
			preOrderReduceCatalogDto.setActivityLimitNumber(0);
			
			reducestocklistforpreorderBean.setCatalogList(Arrays.asList(preOrderReduceCatalogDto));
			reducestocklistforpreorderCall.setData(reducestocklistforpreorderBean);
			reducestocklistforpreorderCall.callService();			
			Logger.verifyEquals("400", reducestocklistforpreorderCall.getString("Code"), "验证code");
			
			ProductDetailsDto productDetailsDto2 = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
			
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getStock(),productDetailsDto2.getCatalogList().get(0).getStock(),"验证库存");
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getRealStock(),productDetailsDto2.getCatalogList().get(0).getRealStock(),"验证真实库存");
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getVirtualStock(),productDetailsDto2.getCatalogList().get(0).getVirtualStock(),"验证虚拟库存");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForPreOrder_009() {
		Logger.start(true, "下单价格价格禁用状态规格,不能下单");
		try {

			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, true);
			addAgentProductBean.getCatalogList().get(0).setVirtualStock(30);
			addAgentProductBean.getCatalogList().get(0).setStock(40);
			addAgentProductBean.getCatalogList().get(0).setAgentPriceList(null);
			addAgentProductBean.getCatalogList().get(0).setDirectPrice(null);
			addAgentProductBean.getCatalogList().get(0).setMarketPrice(0);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			ProductDetailsDto productDetailsDto = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
			
			List<PreOrderReduceCatalogDto> catalogStockList = new ArrayList<PreOrderReduceCatalogDto>();
			PreOrderReduceCatalogDto preOrderReduceCatalogDto = new PreOrderReduceCatalogDto();
			preOrderReduceCatalogDto.setPreOrderId(Long.parseLong(TestDataManager.getRandomNum(10)));
			preOrderReduceCatalogDto.setActivityId(0);
			preOrderReduceCatalogDto.setBuyerId(AgentUsers.csId1);
			preOrderReduceCatalogDto.setCatalogId(productDetailsDto.getCatalogList().get(0).getCatalogId());
			preOrderReduceCatalogDto.setCatalogType(0);
			preOrderReduceCatalogDto.setProductId(productId);
			preOrderReduceCatalogDto.setSellerId(rootUserId);
			preOrderReduceCatalogDto.setBuyCount(10);
			preOrderReduceCatalogDto.setProductLimitNumber(0);
			preOrderReduceCatalogDto.setProductLimitStartTime("0001-01-01T00:00:00");
			preOrderReduceCatalogDto.setActivityLimitNumber(0);
			
			reducestocklistforpreorderBean.setCatalogList(Arrays.asList(preOrderReduceCatalogDto));
			reducestocklistforpreorderCall.setData(reducestocklistforpreorderBean);
			reducestocklistforpreorderCall.callService();			
			Logger.verifyEquals("201", reducestocklistforpreorderCall.getString("Code"), "验证code");
			Logger.verifyIsContains("规格编号不存在", reducestocklistforpreorderCall.getString("Msg"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReduceStockListForPreOrder_010() {
		Logger.start(true, "下单活动商品十件，扣活动库存");
		try {

			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, true);
			addAgentProductBean.getCatalogList().get(0).setVirtualStock(30);
			addAgentProductBean.getCatalogList().get(0).setStock(40);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			AddactivityBean initProductaddactivity = AgentProductCallServiceV2.initProductaddactivity(rootUserId, productId,1,20, false);
			Integer activityId = AgentProductCallServiceV2.agentProductaddactivity(initProductaddactivity);
			
			ProductDetailsDto productDetailsDto = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
			GodProductActivityStock selectByProductId = new GodProductActivityStockWapper().selectByProductIdAndCatalogId(productId, productDetailsDto.getCatalogList().get(0).getCatalogId());
			
			List<PreOrderReduceCatalogDto> catalogStockList = new ArrayList<PreOrderReduceCatalogDto>();
			PreOrderReduceCatalogDto preOrderReduceCatalogDto = new PreOrderReduceCatalogDto();
			preOrderReduceCatalogDto.setPreOrderId(Long.parseLong(TestDataManager.getRandomNum(10)));
			preOrderReduceCatalogDto.setActivityId(activityId);
			preOrderReduceCatalogDto.setBuyerId(AgentUsers.csId1);
			preOrderReduceCatalogDto.setCatalogId(productDetailsDto.getCatalogList().get(0).getCatalogId());
			preOrderReduceCatalogDto.setCatalogType(0);
			preOrderReduceCatalogDto.setProductId(productId);
			preOrderReduceCatalogDto.setSellerId(rootUserId);
			preOrderReduceCatalogDto.setBuyCount(10);
			preOrderReduceCatalogDto.setProductLimitNumber(0);
			preOrderReduceCatalogDto.setProductLimitStartTime("0001-01-01T00:00:00");
			preOrderReduceCatalogDto.setActivityLimitNumber(0);
			
			
			reducestocklistforpreorderBean.setCatalogList(Arrays.asList(preOrderReduceCatalogDto));
			reducestocklistforpreorderCall.setData(reducestocklistforpreorderBean);
			reducestocklistforpreorderCall.callService();
			Logger.verifyEquals("200", reducestocklistforpreorderCall.getString("Code"), "验证code");
			
			ProductDetailsDto productDetailsDto2 = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
			
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getStock(),productDetailsDto2.getCatalogList().get(0).getStock(),"验证库存");
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getRealStock(),productDetailsDto2.getCatalogList().get(0).getRealStock(),"验证真实库存");
			Logger.verifyEquals(productDetailsDto.getCatalogList().get(0).getVirtualStock(),productDetailsDto2.getCatalogList().get(0).getVirtualStock(),"验证虚拟库存");
			GodProductActivityStock selectByProductId1 = new GodProductActivityStockWapper().selectByProductIdAndCatalogId(productId, productDetailsDto.getCatalogList().get(0).getCatalogId());
			Logger.verifyEquals(selectByProductId.getiStockNum()-10,selectByProductId1.getiStockNum(),"验证虚拟库存");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
}